#include "fileSystem.h"


using namespace std;

namespace easyWebServer
{

FileSystem::FileSystem()
{

}

FileSystem::~FileSystem()
{
    if(m_fileFd != -1)
    {
        close(m_fileFd);
    }
    m_fileFd = -1;
}

bool FileSystem::find(const std::string & url)
{
    vector<string> vet;
    boost::split(vet, url, boost::is_any_of("?"));
    m_fileFd = open(vet[0].c_str(), O_RDONLY);
    if(m_fileFd == -1)
    {
        return false;
    }
    return true;
}

size_t FileSystem::getFileSize()
{
    if(m_fileFd == -1) return 0;
    struct stat st;
    fstat(m_fileFd, &st);
    return st.st_size;
}

int FileSystem::getFileFd()
{
    return m_fileFd;
}


}



